package com.xoa.controller.hr;

import com.ibatis.common.resources.Resources;
import com.xoa.model.hr.HrStaffEntry;
import com.xoa.model.hr.HrStaffInfo;
import com.xoa.service.hr.IntroductionService;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 *
 * @作者 李帅帅
 * @创建日期 14:10 2019/9/6
 * @类介绍  人事管理  入职管理
 *
 */
@Controller
@RequestMapping("/personManagement")
public class IntroductionController {
    @Autowired
    private IntroductionService introductionService;
    /*
     * 创建作者:   李 帅 帅
     * 创建日期:   14:11 2019/9/6 0006
     * 方法介绍:   入职管理映射
     * 参数说明:   * @param null
     * @return
     */
    @RequestMapping("/IntroductionManager")
    public String myAttendance(HttpServletRequest request) {
        return "app/hr/personManagement/introduction";
    }
    @RequestMapping("/IntroDuctionQuery")
    public String introductionQuery(HttpServletRequest request) {
        return "app/hr/personManagement/introductionQuery";
    }
    @RequestMapping("/newIntroduction")
    public String newIntroduction(HttpServletRequest request) {
        return "app/hr/personManagement/newIntroduction";
    }
    @RequestMapping("/signSuccess")
    public String signSuccess(HttpServletRequest request) {
        return "app/hr/personManagement/signSuccess";
    }
    @RequestMapping("/IntroductionManagers")
    public String DimissionManagers(HttpServletRequest request) {
        return "app/hr/personManagement/introductionManagers";
    }
    @RequestMapping("/introductionApply")
    public String introductionApply(HttpServletRequest request) {
        return "app/hr/personManagement/introductionApply";
    }
    @RequestMapping("/apply")
    public String apply(HttpServletRequest request) {
        return "app/hr/personManagement/apply";
    }

    @RequestMapping("/sqlIndex")
    public String sqlIndex(HttpServletRequest request) {
        return "app/hr/personManagement/sqlIndex";
    }

    /*
     * 方法介绍:   人事管理查询
     * 参数说明:   [useFlag, pageSize, page, request]
     * @return     com.xoa.util.ToJson<com.xoa.model.hr.HrStaffInfo>
     */
    @RequestMapping("/IntroductionManagerInfo")
    @ResponseBody
    public ToJson<HrStaffInfo> apply(PageParams pageParams, HrStaffEntry hrStaffEntry, HttpServletRequest request, HttpServletResponse response) {
        return introductionService.introductionInfo(pageParams,hrStaffEntry,request,response);
    }


    @ResponseBody
    @RequestMapping("/IntroductionCondition")
    public ToJson<HrStaffInfo> IntroductionConditionQuery(String introductionPerson, String category, String quitTimePlanStart, String quitTimeFactEnd , String brand, String userName, Boolean useFlag, Integer pageSize, Integer page, HttpServletRequest request){
        return introductionService.introductionConditionQuery(introductionPerson,category,quitTimePlanStart,quitTimeFactEnd, brand,userName,useFlag,pageSize,page,request);
    }

/*    @ResponseBody
    @RequestMapping("executeSql")
    public ToJson<Object> executeSql(String sql, String type) throws Exception{
        ToJson<Object> json = new ToJson<>();
        Properties props = Resources.getResourceAsProperties("jdbc-sql.properties");
        String url = props.getProperty("url1001");

        String driver = props.getProperty("driverClassName");
        String username = props.getProperty("uname1001");
        String password = props.getProperty("password1001");

        Class.forName(driver).newInstance();
        Connection conn = DriverManager.getConnection(url, username, password);
        Statement sm = conn.createStatement();
        ResultSet rs = null;

        // 查询
        if(type.equals("1")){

            rs = sm.executeQuery(sql);

            ResultSetMetaData rsmd = rs.getMetaData();

            int columnCount = rsmd.getColumnCount();

            List<String> list = new ArrayList<>();

            while (rs.next()) {

                for (int i = 1; i <= columnCount; i++) {

                    if (!StringUtils.checkNull(rs.getString(i))) {

                        list.add(rs.getString(i).trim());
                    }
                }
            }

            json.setObject(list);
        }else{
            int i1 = sm.executeUpdate(sql);
        }

        json.setFlag(0);

        sm.close();
        conn.close();
        return json;
    }*/
}
